﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using ZLDC.Topo.BLL.Estate;
using System.Text.RegularExpressions;

namespace ZLDC.Estate.TM
{
    public partial class BatchBuildRoom : _PageBase
    {
        RoomNoBLL rbll = new RoomNoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ZLDC.Topo.BLL.Estate.SystemParamBLL.LoadParamType(sType, false, "类型");
                ZLDC.Topo.BLL.Estate.SystemParamBLL.LoadUsage(sUsage, false, "用途");

                int eid = _Request.GetInt("eid", 0);    // 楼盘基本信息ID(t_estate表)
                hEID.Value = eid.ToString();

                lbEstateName.Text = ZLDC.Topo.BLL.Estate.EstateBLL.EstateNameById(eid);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            
            string phases = Phases.Text.Trim();//期数
            string phasesOtherName = PhasesOtherName.Text.Trim();//期数别名
            string phasesOtherNamepy = "";

            string buildname1 = buildName1.Text.Trim();//栋阁名称1
            string buildname2 = buildName2.Text.Trim();//栋阁名称2
            string buildunit = buildUnit.Text.Trim();//栋阁单位

            string dunit1 = dUnit1.Text.Trim();//单元1
            string dunit2 = dUnit2.Text.Trim();//单元2
            string dunit3 = dUnit3.Text.Trim();//单元单位

            int floorTatol = _Convert.ToInt(FloorTotal.Text.Trim());//总层数
            string type = sType.SelectedValue.ToString();//类型
            string usage = sUsage.SelectedValue.ToString();//用途

            int flool1 = _Convert.ToInt(rFloor1.Text.Trim());//房号楼层

            int flool2 = _Convert.ToInt(rFloor2.Text.Trim());//房号楼层

            string roomno1 = roomNo1.Text.Trim();//房号1

            string roomno2 = roomNo2.Text.Trim();//房号2
            //添加房号前缀后缀
            string strPer = iNameFirst.Value;
            string strLast = iNameEnd.Value;
            
            //栋阁前缀后缀

            string buildnameFrist = iBuildNameFirst.Value.Trim();
            string buildnameEnd = iBuildNameEnd.Value.Trim();

            int parentId1 = 0;
            int parentId2 = 0;

            string finalName = lbEstateName.Text.Trim() + phases.Trim();//全名
            int eid = _Convert.ToInt(hEID.Value);//楼盘ID
            string eName = lbEstateName.Text.Trim();
            int isvalid = 1;      // 0有效 1待审核 2无效
            string typeName = "SqAdd";

            // 权限判断
            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("直接添加栋阁"))
            {
                isvalid = 0;
                typeName = "Add";
            }
            //栋阁类型
            string Type = sType.SelectedValue.ToString();

            string username = _Utility.GetInfoBySession().m_sUserName;
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string deptname = _Utility.GetInfoBySession().m_sDeptName;
            int deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID);
            int newid = 0;
            int parentId = 0;
            int rows = 0;
            if (phases != "") //如果期数不为空，则先插入期数
            {
                newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, phasesOtherName, _Utility.GetChineseSpell(phases), _Utility.GetChineseSpell(phasesOtherName), parentId, usage, floorTatol, finalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                if (newid > 0)
                    parentId = newid;
            }
            if (buildname1 != "" && buildname2 != "") //如果栋阁不等于空
            {
                if (_Utility.isExists(buildname1) && _Utility.isExists(buildname2)) //是否是字母
                {
                    int num1 = _Utility.Asc(buildname1);
                    int num2 = _Utility.Asc(buildname2);

                    if (num2 >= num1)
                    {
                        for (int i = num1; i <= num2; i++)//栋阁循环
                        {

                            phases = buildnameFrist + _Utility.Chr(i).ToString() + buildnameEnd + buildunit;//栋阁名称;
                            phasesOtherNamepy = _Utility.GetChineseSpell(phases);//栋阁别名
                            string bfinalName = finalName + phases;//全名
                            newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId, usage, floorTatol, bfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁

                            parentId1 = newid;

                            if (dunit1 != "" && dunit2 != "")
                            {
                                if (_Utility.isExists(dunit1) && _Utility.isExists(dunit2)) //是否是字母
                                {
                                    int unitnum1 = _Utility.Asc(dunit1);//单元
                                    int unitnum2 = _Utility.Asc(dunit2);//单元
                                    if (unitnum2 >= unitnum1)
                                    {
                                        for (int j = unitnum1; j <= unitnum2; j++)//单元循环
                                        {
                                            phases = _Utility.Chr(j).ToString() + buildunit;//单元名称;
                                            phasesOtherNamepy = _Utility.GetChineseSpell(phases);//单元拼音
                                            string dfinalName = bfinalName + phases;//全名


                                            newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId1, usage, floorTatol, dfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁

                                            if (newid > 0)
                                            {
                                                parentId2 = newid;
                                            }
                                            if (flool1 > 0 && flool2 > 0)
                                            {
                                                if (flool2 >= flool1)
                                                {


                                                    for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                                    {
                                                        if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))
                                                        {

                                                            int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                            int roomnum2 = _Utility.Asc(roomno2);//房号

                                                            if (roomnum2 >=roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = _Utility.Chr(k);
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;
                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);

                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else //房号是数字--------------
                                                        {
                                                            int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                            int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                            string number = "1,2,3,4,5,6,7,8,9";
                                                            string roomNo = "";
                                                            if (roomnum2 >= roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    if (number.Contains(k.ToString()))
                                                                    {
                                                                        roomNo = "0" + k;
                                                                    }
                                                                    else
                                                                    {
                                                                        roomNo = k.ToString();
                                                                    }
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = roomNo;
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;
                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }

                                                }
                                            }
                                        }
                                    }

                                }
                                else ///数字--------------------单元 数字
                                {
                                    int unitnum1 = _Convert.ToInt(dunit1);//单元
                                    int unitnum2 = _Convert.ToInt(dunit2);//单元
                                    if (unitnum2 >= unitnum1)
                                    {
                                        for (int j = unitnum1; j <= unitnum2; j++)//单元循环
                                        {
                                            phases = j.ToString() + dunit3;//单元名称;
                                            phasesOtherNamepy = _Utility.GetChineseSpell(phases);//单元拼音
                                            string dfinalName = bfinalName + phases;//全名

                                            newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId1, usage, floorTatol, dfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                                            if (newid > 0)
                                            {
                                                parentId2 = newid;
                                            }

                                            if (flool1 > 0 && flool2 > 0)
                                            {
                                                if (flool2 >= flool1)
                                                {
                                                    for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                                    {
                                                        if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))//-----------房号是字母
                                                        {

                                                            int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                            int roomnum2 = _Utility.Asc(roomno2);//房号

                                                            if (roomnum2 >= roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = _Utility.Chr(k);
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else //房号是数字--------------
                                                        {
                                                            int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                            int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                            string number = "1,2,3,4,5,6,7,8,9";
                                                            string roomNo = "";
                                                            if (roomnum2 >= roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    if (number.Contains(k.ToString()))
                                                                    {
                                                                        roomNo = "0" + k;
                                                                    }
                                                                    else
                                                                    {
                                                                        roomNo = k.ToString();
                                                                    }
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = roomNo;
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                            else //单元等于空
                            {
                                if (flool1 > 0 && flool2 > 0)
                                {
                                    if (flool2 >= flool1)
                                    {
                                        for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                        {
                                            if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))
                                            {

                                                int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                int roomnum2 = _Utility.Asc(roomno2);//房号

                                                if (roomnum2 >= roomnum1)
                                                {
                                                    for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                    {
                                                        int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId1.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                        if (count == 0)
                                                        {
                                                            string strRoomNo = _Utility.Chr(k);
                                                            if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                            if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                            string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                            rows = rbll.AddRoomNos(strRoomNo, "", g, parentId1, bfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                        }
                                                    }
                                                }
                                            }
                                            else //房号是数字--------------
                                            {
                                                int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                string number = "1,2,3,4,5,6,7,8,9";
                                                string roomNo = "";
                                                if (roomnum2 >= roomnum1)
                                                {
                                                    for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                    {
                                                        if (number.Contains(k.ToString()))
                                                        {
                                                            roomNo = "0" + k;
                                                        }
                                                        else
                                                        {
                                                            roomNo = k.ToString();
                                                        }
                                                        int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId1.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                        if (count == 0)
                                                        {
                                                            string strRoomNo = roomNo;
                                                            if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                            if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                            string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                            rows = rbll.AddRoomNos(strRoomNo, "", g, parentId1, bfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                    }
                                }
                            }

                        }
                    }
                }
                else if (IsNumeric(buildname1)>0 || IsNumeric(buildname2)>0) //栋阁是数字
                {
                    int num1 = _Convert.ToInt(buildname1);
                    int num2 = _Convert.ToInt(buildname2);

                    if (num2 >= num1)
                    {
                        for (int i = num1; i <= num2; i++)//栋阁循环
                        {
                            phases =buildnameFrist+ i.ToString() +buildnameEnd+ buildunit;//栋阁名称;
                            phasesOtherNamepy = _Utility.GetChineseSpell(phases);//栋阁别名
                            string bfinalName = finalName + phases;//全名
                            newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId, usage, floorTatol, bfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                            ///
                            if (newid > 0)
                            {
                                parentId1 = newid;
                            }

                            if (dunit1 != "" && dunit2 != "")
                            {
                                if (_Utility.isExists(dunit1) && _Utility.isExists(dunit2)) //是否是字母
                                {
                                    int unitnum1 = _Utility.Asc(dunit1);//单元
                                    int unitnum2 = _Utility.Asc(dunit2);//单元
                                    if (unitnum2 >= unitnum1)
                                    {
                                        for (int j = unitnum1; j <= unitnum2; j++)//单元循环
                                        {
                                            phases = _Utility.Chr(j).ToString() + dunit3;//单元名称;
                                            phasesOtherNamepy = _Utility.GetChineseSpell(phases);//单元拼音
                                            string dfinalName = bfinalName + phases;//全名

                                            newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId1, usage, floorTatol, dfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                                            if (newid > 0)
                                            {
                                                parentId2 = newid;
                                            }

                                            if (flool1 > 0 && flool2 > 0)
                                            {
                                                if (flool2 >= flool1)
                                                {
                                                    for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                                    {
                                                        if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))
                                                        {

                                                            int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                            int roomnum2 = _Utility.Asc(roomno2);//房号

                                                            if (roomnum2 >= roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = _Utility.Chr(k);
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else //房号是数字--------------
                                                        {
                                                            int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                            int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                            string number = "1,2,3,4,5,6,7,8,9";
                                                            string roomNo = "";
                                                            if (roomnum2 >= roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    if (number.Contains(k.ToString()))
                                                                    {
                                                                        roomNo = "0" + k;
                                                                    }
                                                                    else
                                                                    {
                                                                        roomNo = k.ToString();
                                                                    }
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = roomNo;
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }

                                                }
                                            }
                                        }
                                    }
                                    //if (num1 <= num2) //清空
                                    //{
                                    //    parentId = 0;
                                    //}

                                }
                                else ///数字--------------------单元 数字
                                {
                                    int unitnum1 = _Convert.ToInt(dunit1);//单元
                                    int unitnum2 = _Convert.ToInt(dunit2);//单元
                                    if (unitnum2 >= unitnum1)
                                    {
                                        for (int j = unitnum1; j <= unitnum2; j++)//单元循环
                                        {
                                            phases = j.ToString() + dunit3;//单元名称;
                                            phasesOtherNamepy = _Utility.GetChineseSpell(phases);//单元拼音
                                            string dfinalName = bfinalName + phases;//全名

                                            newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId1, usage, floorTatol, dfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                                            if (newid > 0)
                                            {
                                                parentId2 = newid;
                                            }

                                            if (flool1 > 0 && flool2 > 0)
                                            {
                                                if (flool2 >= flool1)
                                                {
                                                    for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                                    {
                                                        if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))//-----------房号是字母
                                                        {

                                                            int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                            int roomnum2 = _Utility.Asc(roomno2);//房号

                                                            if (roomnum2 >= roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = _Utility.Chr(k);
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else //房号是数字--------------
                                                        {
                                                            int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                            int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                            string number = "1,2,3,4,5,6,7,8,9";
                                                            string roomNo = "";
                                                            if (roomnum2 >= roomnum1)
                                                            {
                                                                for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                                {
                                                                    if (number.Contains(k.ToString()))
                                                                    {
                                                                        roomNo = "0" + k;
                                                                    }
                                                                    else
                                                                    {
                                                                        roomNo = k.ToString();
                                                                    }
                                                                    int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                                    if (count == 0)
                                                                    {
                                                                        string strRoomNo = roomNo;
                                                                        if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                        if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                        string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                        rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                            else //---------------单元为空
                            {
                                if (flool1 > 0 && flool2 > 0)
                                {
                                    if (flool2 >= flool1)
                                    {
                                        for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                        {
                                            if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))
                                            {

                                                int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                int roomnum2 = _Utility.Asc(roomno2);//房号

                                                if (roomnum2 >= roomnum1)
                                                {
                                                    for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                    {
                                                        int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId1.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                        if (count == 0)
                                                        {
                                                            string strRoomNo = _Utility.Chr(k);
                                                            if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                            if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                            string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                            rows = rbll.AddRoomNos(strRoomNo, "", g, parentId1, bfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                        }
                                                    }
                                                }
                                            }
                                            else //房号是数字--------------
                                            {
                                                int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                string number = "1,2,3,4,5,6,7,8,9";
                                                string roomNo = "";
                                                if (roomnum2 >= roomnum1)
                                                {
                                                    for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                    {
                                                        if (number.Contains(k.ToString()))
                                                        {
                                                            roomNo = "0" + k;
                                                        }
                                                        else
                                                        {
                                                            roomNo = k.ToString();
                                                        }
                                                        int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId1.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                        if (count == 0)
                                                        {
                                                            string strRoomNo = roomNo;
                                                            if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                            if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                            string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                            rows = rbll.AddRoomNos(strRoomNo, "", g, parentId1, bfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                    }
                                }
                            }

                        }
                    }


                }
                else //中文，其它
                {
                    phases =buildnameFrist + buildname1 +buildnameEnd + buildunit;//栋阁名称;
                    phasesOtherNamepy = _Utility.GetChineseSpell(phases);//栋阁别名
                    string bfinalName = finalName + phases;//全名
                    newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId, usage, floorTatol, bfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                    ///
                    if (newid > 0)
                    {
                        parentId1 = newid;
                    }

                    if (dunit1 != "" && dunit2 != "")
                    {
                        if (_Utility.isExists(dunit1) && _Utility.isExists(dunit2)) //是否是字母
                        {
                            int unitnum1 = _Utility.Asc(dunit1);//单元
                            int unitnum2 = _Utility.Asc(dunit2);//单元
                            if (unitnum2 >= unitnum1)
                            {
                                for (int j = unitnum1; j <= unitnum2; j++)//单元循环
                                {
                                    phases = _Utility.Chr(j).ToString() + dunit3;//单元名称;
                                    phasesOtherNamepy = _Utility.GetChineseSpell(phases);//单元拼音
                                    string dfinalName = bfinalName + phases;//全名

                                    newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId1, usage, floorTatol, dfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                                    if (newid > 0)
                                    {
                                        parentId2 = newid;
                                    }

                                    if (flool1 > 0 && flool2 > 0)
                                    {
                                        if (flool2 >= flool1)
                                        {
                                            for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                            {
                                                if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))
                                                {

                                                    int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                    int roomnum2 = _Utility.Asc(roomno2);//房号

                                                    if (roomnum2 >= roomnum1)
                                                    {
                                                        for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                        {
                                                            int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                            if (count == 0)
                                                            {
                                                                string strRoomNo = _Utility.Chr(k);
                                                                if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                            }
                                                        }
                                                    }
                                                }
                                                else //房号是数字--------------
                                                {
                                                    int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                    int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                    string number = "1,2,3,4,5,6,7,8,9";
                                                    string roomNo = "";
                                                    if (roomnum2 >= roomnum1)
                                                    {
                                                        for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                        {
                                                            if (number.Contains(k.ToString()))
                                                            {
                                                                roomNo = "0" + k;
                                                            }
                                                            else
                                                            {
                                                                roomNo = k.ToString();
                                                            }
                                                            int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                            if (count == 0)
                                                            {
                                                                string strRoomNo = roomNo;
                                                                if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                        }
                                    }
                                }
                            }
                            //if (num1 <= num2) //清空
                            //{
                            //    parentId = 0;
                            //}

                        }
                        else ///数字--------------------单元 数字
                        {
                            int unitnum1 = _Convert.ToInt(dunit1);//单元
                            int unitnum2 = _Convert.ToInt(dunit2);//单元
                            if (unitnum2 >= unitnum1)
                            {
                                for (int j = unitnum1; j <= unitnum2; j++)//单元循环
                                {
                                    phases = j.ToString() + dunit3;//单元名称;
                                    phasesOtherNamepy = _Utility.GetChineseSpell(phases);//单元拼音
                                    string dfinalName = bfinalName + phases;//全名

                                    newid = ZLDC.Topo.BLL.Estate.BuildBLL.EstateAndRoomNOSave(0, phases, "", phasesOtherNamepy, "", parentId1, usage, floorTatol, dfinalName, eid, eName, "", isvalid, username, userid, deptname, deptId, Type);///保存栋阁
                                    if (newid > 0)
                                    {
                                        parentId2 = newid;
                                    }

                                    if (flool1 > 0 && flool2 > 0)
                                    {
                                        if (flool2 >= flool1)
                                        {
                                            for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                            {
                                                if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))//-----------房号是字母
                                                {

                                                    int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                                    int roomnum2 = _Utility.Asc(roomno2);//房号

                                                    if (roomnum2 >= roomnum1)
                                                    {
                                                        for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                        {
                                                            int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                            if (count == 0)
                                                            {
                                                                string strRoomNo = _Utility.Chr(k);
                                                                if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                            }
                                                        }
                                                    }
                                                }
                                                else //房号是数字--------------
                                                {
                                                    int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                                    int roomnum2 = _Convert.ToInt(roomno2);//房号
                                                    string number = "1,2,3,4,5,6,7,8,9";
                                                    string roomNo = "";
                                                    if (roomnum2 >= roomnum1)
                                                    {
                                                        for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                                        {
                                                            if (number.Contains(k.ToString()))
                                                            {
                                                                roomNo = "0" + k;
                                                            }
                                                            else
                                                            {
                                                                roomNo = k.ToString();
                                                            }
                                                            int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId2.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                            if (count == 0)
                                                            {
                                                                string strRoomNo = roomNo;
                                                                if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                                if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                                string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                                rows = rbll.AddRoomNos(strRoomNo, "", g, parentId2, dfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }
                    else //-------------------单元为空
                    {
                        if (flool1 > 0 && flool2 > 0)
                        {
                            if (flool2 >= flool1)
                            {
                                for (int g = flool1; g <= flool2; g++)//房号楼层循环
                                {
                                    if (_Utility.isExists(roomno1) && _Utility.isExists(roomno2))
                                    {

                                        int roomnum1 = _Utility.Asc(roomno1);//房号                                                           
                                        int roomnum2 = _Utility.Asc(roomno2);//房号

                                        if (roomnum2 >= roomnum1)
                                        {
                                            for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                            {
                                                int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId1.ToString(), g.ToString(), _Utility.Chr(k));//判断房号是否存在
                                                if (count == 0)
                                                {
                                                    string strRoomNo = _Utility.Chr(k);
                                                    if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                    if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                    string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                    rows = rbll.AddRoomNos(strRoomNo, "", g, parentId1, bfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                }
                                            }
                                        }
                                    }
                                    else //房号是数字--------------
                                    {
                                        int roomnum1 = _Convert.ToInt(roomno1);//房号                                                           
                                        int roomnum2 = _Convert.ToInt(roomno2);//房号
                                        string number = "1,2,3,4,5,6,7,8,9";
                                        string roomNo = "";
                                        if (roomnum2 >= roomnum1)
                                        {
                                            for (int k = roomnum1; k <= roomnum2; k++)//房号循环
                                            {
                                                if (number.Contains(k.ToString()))
                                                {
                                                    roomNo = "0" + k;
                                                }
                                                else
                                                {
                                                    roomNo = k.ToString();
                                                }
                                                int count = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRooms(parentId1.ToString(), g.ToString(), roomNo);//判断房号是否存在
                                                if (count == 0)
                                                {
                                                    string strRoomNo = roomNo;
                                                    if (!string.IsNullOrEmpty(strPer)) strRoomNo = strPer + strRoomNo;
                                                    if (!string.IsNullOrEmpty(strLast)) strRoomNo = strRoomNo + strLast;

                                                    string roomNonamepy = _Utility.GetChineseSpell(strRoomNo);
                                                    rows = rbll.AddRoomNos(strRoomNo, "", g, parentId1, bfinalName, "", typeName, "", usage, this.info.m_sUserName.ToString(), this.info.m_sDeptName.ToString(), this.info.m_sDeptID.ToString(), "0", "", "", isvalid);
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }

                }


            }
            if (rows > 0)
                Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "alert('操作成功！')", true);
            else
                Page.ClientScript.RegisterStartupScript(this.GetType(), "message", "alert('操作失败！')", true);

            btnSave.Enabled = true;
            btnSave.Text = "保存";
        
        }


        /// <summary>
        /// 判断输入的是否是数字
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public int IsNumeric(string str)
        {
            int i;
            if (str != null && Regex.IsMatch(str, @"^\d+$"))
                i = int.Parse(str);
            else
                i = -1;
            return i;
        } 

    }
}
